package com.zw.controller;

import com.zw.dto.AddBasicDataDto;
import com.zw.dto.CloudComputingDto;
import com.zw.entity.BasicData;
import com.zw.service.BasicDataService;
import com.zw.utils.RSAUtils;
import com.zw.vo.CloudComputingVO;
import com.zw.vo.LoginBody;
import com.zw.vo.ResponseVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.security.PrivateKey;

/**
 * (BasicData)表控制层
 *
 * @author makejava
 * @since 2025-03-25 23:32:03
 */
@RestController
@RequestMapping("basicData")
@Api(value = "数据相关API", tags = "数据相关API")
public class BasicDataController {
    /**
     * 服务对象
     */
    @Resource
    private BasicDataService basicDataService;

    /**
     * 上传数据
     *
     * @param dto 上传数据请求dto
     * @return 结果
     */
    @ApiOperation("上传数据")
    @PostMapping("/addBasicData")
    public ResponseVO<Boolean> addBasicData(@RequestBody @Valid AddBasicDataDto dto) {
        try {
            Boolean addRes = basicDataService.addBasicData(dto);
            return new ResponseVO(addRes);
        } catch (Exception e) {
            e.printStackTrace();
            if (e instanceof RuntimeException){
                throw new RuntimeException(e.getMessage());
            }
            throw new RuntimeException("上传数据失败，请联系管理员处理！");
        }
    }

    /**
     * 云端计算
     *
     * @param dto 上传数据请求dto
     * @return 结果
     */
    @ApiOperation("云端计算")
    @PostMapping("/cloudComputing")
    public ResponseVO<CloudComputingVO> cloudComputing(@RequestBody @Valid CloudComputingDto dto) {
        try {
            CloudComputingVO cloudComputing = basicDataService.cloudComputing(dto);
            return new ResponseVO(cloudComputing);
        } catch (Exception e) {
            e.printStackTrace();
            if (e instanceof RuntimeException){
                throw new RuntimeException(e.getMessage());
            }
            throw new RuntimeException("云端计算失败，请联系管理员处理！");
        }
    }

}

